/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function initNewCandidate(){
    $('.curtains').curtain({
        scrollSpeed: 400,
        controls: '.menu'
    });
    
    $('.blueBG').imagesLoaded(function(){
        $('.blobText').css('width',($(".blobPicture").css('width')));
    });
    $(window).resize(function() {
        $('.blobText').css('width',($(".blobPicture").css('width')));
    });
}


var width;
var height;
var previewWidth;
var previewHeight;
//var formId="createCandidateForm\\:accordionPanel";
var formId="picturesForm";
var divPreview
var formulario;

function iniciarPaginaCrop(widthVar,heightVar){
    previewWidth=250;
    previewHeight=250;
    formulario=0;
    width=widthVar;
    height=heightVar;
    var x;
    x=$(document);
    x.ready(inicializarEventosCrop);
}

function iniciarPaginaCropParams(widthVar,heightVar,previewWidthVar, previewHeightVar,formularioVar){
    previewWidth=previewWidthVar;
    previewHeight=previewHeightVar;
    width=widthVar;
    height=heightVar;
    var x;
    x=$(document);
    formulario=formularioVar;
    x.ready(inicializarEventosCrop);
}

function inicializarEventosCrop(){
    image=$(".divOriginalImage").find('img');
    image.Jcrop({
                onChange: showPreview,
		onSelect: finishedSelection,
		aspectRatio: previewWidth/previewHeight,
                setSelect: [ width/2-previewWidth/2, height/2-previewHeight/2, previewWidth, previewHeight ]
    });
}
function showPreview(coords)
{
	var rx = previewWidth / coords.w;
	var ry = previewHeight / coords.h;
        image=$(".divPreview").find('img');
	image.css({
		width: Math.round(rx * width) + 'px',
		height: Math.round(ry * height) + 'px',
		marginLeft: '-' + Math.round(rx * coords.x) + 'px',
		marginTop: '-' + Math.round(ry * coords.y) + 'px'
	});
        
}

function finishedSelection(coords){
    if(formulario==0){
        $("#"+formId+"\\:x1").val(Math.round(coords.x));
        $("#"+formId+"\\:x2").val(Math.round(coords.x2));
        $("#"+formId+"\\:y1").val(Math.round(coords.y));
        $("#"+formId+"\\:y2").val(Math.round(coords.y2));
        $("#"+formId+"\\:cropWidth").val(Math.round(coords.w));
        $("#"+formId+"\\:cropHeight").val(Math.round(coords.h));
    }
    else{
        $("#"+formId+"\\:form"+formulario+"x1").val(Math.round(coords.x));
        $("#"+formId+"\\:form"+formulario+"x2").val(Math.round(coords.x2));
        $("#"+formId+"\\:form"+formulario+"y1").val(Math.round(coords.y));
        $("#"+formId+"\\:form"+formulario+"y2").val(Math.round(coords.y2));
        $("#"+formId+"\\:form"+formulario+"cropWidth").val(Math.round(coords.w));
        $("#"+formId+"\\:form"+formulario+"cropHeight").val(Math.round(coords.h));
    }
        
}